package com.emergency.evaluate.controller;

import com.emergency.common.entity.Result;
import com.emergency.common.entity.StatusCode;
import com.emergency.evaluate.domain.Auto;
import com.emergency.evaluate.domain.Autoscore;
import com.emergency.evaluate.domain.Manual;
import com.emergency.evaluate.domain.Report;
import com.emergency.evaluate.service.AutoService;
import com.emergency.evaluate.service.AutoscoreService;
import com.emergency.evaluate.service.ManualService;
import com.emergency.evaluate.service.ReportService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Created by lijie on 2019/10/23.
 */
@RestController
@RequestMapping("/rating")
@Api(value="评估打分类",description = "分为三类，自动评估、人工评估、综合评估")
public class RatingController {

    @Autowired
    private ManualService manualService;
    @Autowired
    private AutoscoreService autoscoreService;
    @Autowired
    private AutoService autoService;
   @Autowired
   private ReportService reportService;

    //1.添加或修改评分表及分数
    @ApiOperation(value = "添加评分表信息接口" ,  notes="添加评分表信息 自动、人工、综合")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "manual", value = "评分表", required = true, paramType = "query", dataType = "Manual"),
    })
    @RequestMapping(value = "manual/add",method = RequestMethod.POST)
    public Result add(@RequestBody Manual manual){
        List <Manual> manualList = manualService.add ( manual );
        return new Result(true, StatusCode.OK,  "操作成功", manualList);
    }

    //2.输入评分表ID查询评分表及分数
    @ApiOperation(value = "查询评分表信息接口" ,  notes="查询评分表信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "manualId", value = "评分表Id", required = true, paramType = "query", dataType = "Long"),
    })
    @RequestMapping(value = "manual/get/{manualId}",method = RequestMethod.POST)
    public Result get(@PathVariable Long manualId){
        Manual manual = manualService.get(manualId);
        return new Result(true, StatusCode.OK,  "操作成功",manual);
    }

    //3.根据编号删除评分表
    @ApiOperation(value = "删除评分表信息接口" ,  notes="删除评分表信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "manualId", value = "评分表Id", required = true, paramType = "query", dataType = "Long"),
    })
    @RequestMapping(value = "manual/del/{manualId}",method = RequestMethod.POST)
    public Result del(@PathVariable Long manualId){
        manualService.delete(manualId);
        return new Result(true, StatusCode.OK,  "操作成功");
    }

    //4.根据人工评分表ID生成评估报告
    @ApiOperation(value = "评估报告信息接口" ,  notes="查询评估报告信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "reportId", value = "评估报告Id", required = true, paramType = "query", dataType = "Long"),
    })
    @RequestMapping(value = "report/add/{manualID}",method = RequestMethod.POST)
    public Result addReport(@PathVariable Long manualID){
        List<Report> reports= reportService.save (manualID);//增加或修改打分表后自动生成评估报告并查看
        return new Result(true, StatusCode.OK,  "操作成功",reports);
    }

    //5.输入评分表ID查询评分表及分数
    @ApiOperation(value = "生成评分表信息接口" ,  notes="生成评分报告信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "reportId", value = "评分报告Id", required = true, paramType = "query", dataType = "Long"),
    })
    @RequestMapping(value = "report/get/{reportId}",method = RequestMethod.POST)
    public Result getReport(@PathVariable Long reportId){
        Report report=reportService.get(reportId);
        return new Result(true, StatusCode.OK,  "操作成功",report);
    }

  //6. 获取自动评分数据

    @ApiOperation(value = "获取自动评分数据接口" ,  notes="获取自动评分数据信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "autoscorelist", value = "获取自动评分list", required = true, paramType = "query", dataType = "Long"),
    })
    @RequestMapping(value = "autoscore/get",method = RequestMethod.POST)
    public Result getAuto(@RequestBody List<Autoscore> autoscoreList){
        List <Autoscore> list = autoscoreService.add ( autoscoreList );
        return new Result(true, StatusCode.OK,  "操作成功",list);
    }

    //7. 自动评分
    @ApiOperation(value = "自动评分接口" ,  notes="自动评分")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "autoscorelist", value = "自动评分list", required = true, paramType = "query", dataType = "Long"),
    })
    @RequestMapping(value = "auto/add",method = RequestMethod.POST)
    public Result addAuto(@RequestBody Auto auto){
        List <Auto> autolist = autoService.add ( auto );
        return new Result(true, StatusCode.OK,  "操作成功",autolist);
    }
    //8.输入评分表ID查询评分表及分数
    @ApiOperation(value = "查询系统评分表信息接口" ,  notes="查询系统评分表信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "autoId", value = "系统评分表Id", required = true, paramType = "query", dataType = "Long"),
    })
    @RequestMapping(value = "auto/get/{autoId}",method = RequestMethod.POST)
    public Result getauto(@PathVariable Long autoId){
        Auto auto = autoService.get ( autoId );
        return new Result(true, StatusCode.OK,  "操作成功",auto);
    }
    //9.根据编号删除系统评分表
    @ApiOperation(value = "删除评分表信息接口" ,  notes="删除评分表信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "autoId", value = "评分表Id", required = true, paramType = "query", dataType = "Long"),
    })
    @RequestMapping(value = "auto/del/{autoId}",method = RequestMethod.POST)
    public Result delauto(@PathVariable Long autoId ){
        autoService.delete(autoId);
        return new Result(true, StatusCode.OK,  "操作成功");
    }

    //4.根据人工评分表ID生成评估报告
    @ApiOperation(value = "评估报告信息接口" ,  notes="查询评估报告信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "reportId", value = "评估报告Id", required = true, paramType = "query", dataType = "Long"),
    })
    @RequestMapping(value = "report/addauto/{autoID}",method = RequestMethod.POST)
    public Result addautoReport(@PathVariable Long autoID){
        List<Report> reports= reportService.saveauto (autoID);//增加或修改打分表后自动生成评估报告并查看
        return new Result(true, StatusCode.OK,  "操作成功",reports);
    }
}
